package thread;

public class JoinThread extends Thread {
    public JoinThread(String name){
        super(name);
    }
    @Override
    public void run() {
        for (int i = 0; i < 10; i++) {
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(getName()+"  "+i);
        }
    }

    public static void main(String[] args){
        new JoinThread("新线程").start();;
        for (int i = 0; i < 10; i++) {
            if (i==5){
                JoinThread joinThread = new JoinThread("被join的线程");
                joinThread.start();;
                try {
                    joinThread.join();
//                    joinThread.join(300);
//                    joinThread.join(300,500);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            System.out.println(Thread.currentThread().getName()+"  "+i);
        }
    }
}
